package com.evolution.warlock.controller.admin;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.evolution.warlock.entity.Admin;
import com.evolution.warlock.entity.CivilDispute;
import com.evolution.warlock.entity.CriminalBase;
import com.evolution.warlock.entity.MasterConfig.KeyType;
import com.evolution.warlock.service.AdminService;
import com.evolution.warlock.service.CivilDisputeService;
import com.evolution.warlock.service.CriminalBaseService;
import com.evolution.warlock.service.MasterConfigService;

@Controller("civilDisputeController")
@RequestMapping("/admin/civildispute")
public class CivilDisputeController extends BaseController {
	
	@Resource(name = "masterConfigServiceImpl")
	private MasterConfigService masterConfigService;
	@Resource(name = "civilDisputeServiceImpl")
	private CivilDisputeService civilDisputeService;
	@Resource(name = "adminServiceImpl")
	private AdminService adminService;
	@Resource(name = "criminalBaseServiceImpl")
	private CriminalBaseService criminalBaseService;	

	/**
	 * 增加
	 */
	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public String add(String criminalNumber, ModelMap model) {
		
//	   CriminalBase criminalBase = criminalBaseService.findCriminalBase(Long.valueOf(criminalNumber));
	   
	   System.out.println("criminalNumber  :"+criminalNumber);
	   
//	   model.addAttribute("name", criminalBase.getName());
//	   model.addAttribute("gender", criminalBase.getGender());
//	   model.addAttribute("idCardNum", criminalBase.getIdCardNum());
//	   
//	   
//	   model.addAttribute("criminalNumber", criminalBase.getCriminalNumber());
//	   model.addAttribute("departmentName", criminalBase.getPolicerDepartment());
//	   model.addAttribute("policerName", criminalBase.getPolicerName());
		 
	   model.addAttribute("genderGroup", masterConfigService.findList(KeyType.GENDER.getValue()));
	   model.addAttribute("involedCategoryGroup", masterConfigService.findList(KeyType.INVOLVED_CATEGORY.getValue()));
	   model.addAttribute("civilDisputeGroup", masterConfigService.findList(KeyType.CIVIL_DISPUTE.getValue()));
	   model.addAttribute("civilDisputeConditionGroup", masterConfigService.findList(KeyType.CIVIL_DISPUTE_CONDITION.getValue()));
	   model.addAttribute("civilDisputeResultGroup", masterConfigService.findList(KeyType.CIVIL_DISPUTE_RESULT.getValue()));
	   model.addAttribute("civilDisputeTimeStampGroup", masterConfigService.findList(KeyType.CIVIL_DISPUTE_TIMESTAMP.getValue()));
	   model.addAttribute("caseCategoryGroup", masterConfigService.findList(KeyType.CASE_CATEGORY.getValue()));
	   model.addAttribute("reasonGroup", masterConfigService.findList(KeyType.REASON_GROUP.getValue()));
		 
	   return "/admin/civildispute/add";
	 }
	
	/**
	 * 保存
	 */
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public String save(CivilDispute civilDispute, RedirectAttributes redirectAttributes) {
		

	    
		civilDisputeService.save(civilDispute);
		
		addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
		return "redirect:/admin/criminalbase/list.jhtml";
	}
	
	/**
	 * 查看
	 */
	@RequestMapping(value = "/view", method = RequestMethod.GET)
	public String view(String criminalNumber, ModelMap model) {
		
      CivilDispute civilDispute = civilDisputeService.findCivilDispute(Long.valueOf(criminalNumber));
      
//	  model.addAttribute("idCardNum", criminalBase.getIdCardNum());
//	  model.addAttribute("gender", criminalBase.getGender());
//	  model.addAttribute("name", criminalBase.getName());
	  model.addAttribute("genderGroup", masterConfigService.findList(KeyType.GENDER.getValue()));
	  model.addAttribute("involedCategoryGroup", masterConfigService.findList(KeyType.INVOLVED_CATEGORY.getValue()));
	  model.addAttribute("civilDisputeGroup", masterConfigService.findList(KeyType.CIVIL_DISPUTE.getValue()));
	  model.addAttribute("civilDisputeConditionGroup", masterConfigService.findList(KeyType.CIVIL_DISPUTE_CONDITION.getValue()));
	  model.addAttribute("civilDisputeResultGroup", masterConfigService.findList(KeyType.CIVIL_DISPUTE_RESULT.getValue()));
	  model.addAttribute("civilDisputeTimeStampGroup", masterConfigService.findList(KeyType.CIVIL_DISPUTE_TIMESTAMP.getValue()));
	  model.addAttribute("caseCategoryGroup", masterConfigService.findList(KeyType.CASE_CATEGORY.getValue()));
	  model.addAttribute("reasonGroup", masterConfigService.findList(KeyType.REASON_GROUP.getValue()));
	  model.addAttribute("civilDispute", civilDispute);
	  return "/admin/civildispute/view";
	}
	
	/**
	 * 编辑
	 */
	@RequestMapping(value = "/edit", method = RequestMethod.GET)
	public String edit(String criminalNumber, ModelMap model) {
	   
	   CivilDispute civilDispute = civilDisputeService.findCivilDispute(Long.valueOf(criminalNumber));
	   model.addAttribute("genderGroup", masterConfigService.findList(KeyType.GENDER.getValue()));
	   model.addAttribute("involedCategoryGroup", masterConfigService.findList(KeyType.INVOLVED_CATEGORY.getValue()));
	   model.addAttribute("civilDisputeGroup", masterConfigService.findList(KeyType.CIVIL_DISPUTE.getValue()));
	   model.addAttribute("civilDisputeConditionGroup", masterConfigService.findList(KeyType.CIVIL_DISPUTE_CONDITION.getValue()));
	   model.addAttribute("civilDisputeResultGroup", masterConfigService.findList(KeyType.CIVIL_DISPUTE_RESULT.getValue()));
	   model.addAttribute("civilDisputeTimeStampGroup", masterConfigService.findList(KeyType.CIVIL_DISPUTE_TIMESTAMP.getValue()));
	   model.addAttribute("caseCategoryGroup", masterConfigService.findList(KeyType.CASE_CATEGORY.getValue()));
	   model.addAttribute("reasonGroup", masterConfigService.findList(KeyType.REASON_GROUP.getValue()));
	   model.addAttribute("civilDispute", civilDispute);
	   return "/admin/civildispute/edit";
	}
	
	/**
	 * 更新
	 */
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	public String update(CivilDispute civilDispute, RedirectAttributes redirectAttributes) {
		
    civilDisputeService.update(civilDispute);
    addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
    return "redirect:/admin/criminalbase/list.jhtml";
  }
	
}
